using SBPweb.Data.Generic;

namespace SBPweb.Data
{
	/// <summary>
	/// This class handles the object polymorphism for generic repositories
	/// </summary>
	/// <typeparam name="TDomainObject">Domain object of repository</typeparam>
	public class RepositoryWrapper<TDomainObject> : IRepository<IEntity> where TDomainObject : IEntity
	{
		private IRepository<TDomainObject> mRepository;

		/// <summary>
		/// Initializes a new RepositoryWrapper instance
		/// </summary>
		/// <param name="repository">IRepository&lt;TDomainObject&gt; that wrapped by this instance</param>
		public RepositoryWrapper(IRepository<TDomainObject> repository)
		{
			mRepository = repository;
		}

		#region IRepository<IEntity> Members

		/// <summary>
		/// Commits transaction
		/// </summary>
		/// <param name="item">item to commit</param>
		public void Commit(IEntity item)
		{
			mRepository.Commit((TDomainObject)item);
		}

		/// <summary>
		/// Rollbacks transaction
		/// </summary>
		/// <param name="item">item to rollback</param>
		public void Rollback(IEntity item)
		{
			mRepository.Rollback((TDomainObject)item);
		}

		/// <summary>
		/// Begins transaction
		/// </summary>
		public void BeginTransaction()
		{
			mRepository.BeginTransaction();
		}

		#endregion
	}
}
